<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://xmlns.jcp.org/jsf/passthrough"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputLabel value="#{messages.Message}"/>
        </ui:define>
        <ui:define name="body">
            <h:outputScript library="javaScript" name="d3.v4.js" target="head"/>
            <h:outputScript library="javaScript" name="graphlib-dot.js" target="head"/>
            <h:outputScript library="javaScript" name="dagre-d3.js" target="head"/>
            <h:outputStylesheet library="css" name="dagre.css"/>
            <h:outputScript library="javaScript" name="remoteMathJax.js" target="head"/>
            <h:outputScript library="javaScript" name="remoteMathJax.js" target="head"/>
            <h:form prependId="false">
                <h:panelGrid columns="2">
                    <h:outputLabel>#{messages.Subject}</h:outputLabel>
                    <h:selectOneMenu id="subject" value="#{subjectController.selected}" 
                                     required="true" requiredMessage="#{messages.Select}#{messages.Subject}" >
                        <f:selectItem itemLabel="#{messages.Please}#{messages.Select}"/>
                        <f:selectItems value="#{subjectController.getSubjectList(1)}"/>
                        <f:ajax render="@form" />
                    </h:selectOneMenu>
                </h:panelGrid>
                <h:panelGrid columns="1" id="knowledge" rendered="#{!subjectController.isSelectedNull()}">
                    <h:outputLabel>#{messages.Knowledge}</h:outputLabel>
                    <h:selectOneListbox  value="#{knowledgeController.selected}" immediate="true"  size="4">
                        <f:selectItems value="#{knowledgeController.knowledgeList4Subject}"/>
                        <f:ajax render="@form" />
                    </h:selectOneListbox>
                </h:panelGrid>
                <h:panelGrid columns="1" id="detail"  rendered="#{!knowledgeController.isSelectedNull()}">
                    <h:outputLabel value="#{knowledgeController.selected.name}" style="font-size: 20px; background: #d9edf7"/>
                    <h:outputText escape="false"  value="#{knowledgeController.selected.details}"/>
                    <ui:include src="../learningResource/resource4Knowledge.xhtml"/>
                    <c:forEach items="#{edgeamongknowledgeController.getPrecessorEdgeamongknowledge(knowledgeController.selected)}" var="edge">
                        <h:commandLink action="#{knowledgeController.resetSelected(edge.predecessornode)}">
                            <h:outputLabel value="#{edge.predicate.pname}"/>
                            <h:outputLabel value="#{edge.predecessornode.name}"/>
                            <f:ajax render="knowledge detail" />
                        </h:commandLink>
                    </c:forEach>
                    <c:forEach items="#{edgeamongknowledgeController.getSuccorEdgeamongknowledge(knowledgeController.selected)}" var="edge">
                        <h:commandLink action="#{knowledgeController.resetSelected(edge.predecessornode)}">
                            <h:outputLabel value="#{messages.As}#{edge.predicate.pname}"/>
                            <h:outputLabel value="#{edge.predecessornode.name}"/>
                            <f:ajax render="knowledge detail" />
                        </h:commandLink>
                    </c:forEach>

                    <c:forEach items="#{knowledgeController.selected.questionSet}" var="temQuestion" >
                        <hr/>
                        <!--下面显示题目-->
                        <h:outputLabel value="" rendered="#{questionController.prepareSecondContent(temQuestion)}"/>
                        <h:outputLabel value="#{messages.QuestionTitle}:"/>
                        <h:inputTextarea value="#{questionController.selected.valueinfo}"   p:id="myeditor" readonly="true"/>
                        <h:panelGrid columns="1">
                            <c:if test="#{questionController.hasFigure(temQuestion)}">
                                <h:graphicImage value="#{publicFields.fileRepository}#{questionController.imageURL()}" width="320px" height="180px" style="float:left"/>
                            </c:if>
                        </h:panelGrid>
                        <h:outputLabel value="#{messages.Answer}:"/>
                        <h:panelGroup >
                            <h:inputTextarea value="#{questionController.selected.answer}" readonly="true"
                                             rendered="#{questionControllerA.isTextare(questionController.selected.type)}"/>

                            <h:panelGrid columns="2" rendered="#{questionControllerA.isSelectionQuestion(questionController.selected.type)}">
                                A.<h:inputTextarea  value="#{questionController.selectionString1}"  readonly="true"/>
                                B.<h:inputTextarea value="#{questionController.selectionString2}"   readonly="true"/>
                                C.<h:inputTextarea value="#{questionController.selectionString3}"   readonly="true"/>
                                D.<h:inputTextarea value="#{questionController.selectionString4}"  readonly="true"/>
                                E.<h:inputTextarea value="#{questionController.selectionString5}"   readonly="true" 
                                                   rendered="#{questionControllerA.isMultiSelection(questionController.selected.type)}"/>
                            </h:panelGrid>
                            <!--单选题-->
                            <h:selectOneRadio value="#{questionController.selected.answer}" readonly="true" 
                                              rendered="#{questionControllerA.isSingleSelection(questionController.selected.type)}">
                                <f:selectItems value="#{questionControllerA.secondContentOptions(questionController.selected.type)}"/>
                            </h:selectOneRadio>
                            <!-- 多选题 -->
                            <h:selectManyCheckbox value="#{questionController.multSelectionStrings}" readonly="true"
                                                  rendered="#{questionControllerA.isMultiSelection(questionController.selected.type)}">
                                <f:selectItems value="#{questionControllerA.secondContentOptions(questionController.selected)}"/>
                            </h:selectManyCheckbox>
                            <!-- 判断题 -->
                            <h:selectOneRadio value="#{questionController.selected.answer}" readonly="true"
                                              rendered="#{questionControllerA.isJudgment(questionController.selected.type)}"> 
                                <f:selectItems value="#{questionControllerA.trueOrFalsItems}"/>
                            </h:selectOneRadio>

                            <!-- 客观编程题  -->
                            <h:panelGrid columns="1" rendered="#{questionControllerA.isObjectiveProgram(questionController.selected.type)}">
                                <h:inputTextarea value="#{questionController.selected.answer}" readonly="true"  p:id="myeditor"/>
                                <h:outputLabel value="#{messages.TestData}#{messages.Input}#{messages.Split}#{messages.With}+++"/>
                                <h:inputTextarea value="#{questionController.inputDataString}" readonly="true"  p:id="myeditor"/>
                                <h:outputLabel value="#{messages.TestData}#{messages.Output}#{messages.Split}#{messages.With}+++"/>
                                <h:inputTextarea value="#{questionController.outputDataString}" readonly="true"  p:id="myeditor"/>
                            </h:panelGrid>

                        </h:panelGroup>
                        <!--主观编程题-->
                        <h:panelGroup rendered="#{questionControllerA.isSubjectiveProgram(questionController.selected.type)}">
                            <h:inputTextarea value="#{questionController.selected.answer}" readonly="true"  p:id="myeditor"/>
                            <h:outputLabel value="#{messages.If}#{messages.Have},#{messages.Upload}#{messages.Image}"/>
                            <h:inputFile value="#{questionController.answerFile}" rendered="true"/>
                        </h:panelGroup>


                        <h:panelGrid columns="2">
                            <h:outputLabel value="#{messages.Analysis}:"/>
                            <h:outputText escape="false"    value="#{questionController.selected.analysis}" title="#{messages.Analysis}" id="myeditor"/>
                            <h:outputLabel value="#{messages.Refer}:"/>
                            <h:outputText escape="false"    value="#{questionController.selected.refer}" title="#{messages.Refer}"/>
                        </h:panelGrid>
                    </c:forEach>

                    <h:commandButton value="#{messages.Create}" action="#{questionController.prepareCreate()}" immediate="true" />
                    <h:commandButton value="#{messages.View} #{messages.All}" action="#{questionController.prepareList()}" immediate="true"/>
                    <h:commandButton action="#{questionController.prepareEdit}" value="#{messages.Edit}"  rendered="#{reexaminationController.isEditable(null, questionController.selected)}"/>
                </h:panelGrid>
                <h:inputHidden p:id="inputGraph" p:name="inputGraph" value="#{knowledgeController.getKnowledgeRelationship4dagre()}" />

                <svg width="960" height="600" id="svg"> <g/></svg>
                <script>
                    var svg = d3.select("svg"),
                            inner = d3.select("svg g"),
                            zoom = d3.zoom().on("zoom", function () {
                        inner.attr("transform", d3.event.transform);
                    });
                    svg.call(zoom);

                    // Create and configure the renderer
                    var render = dagreD3.render();

                    var g;

                    var inputGraph = document.querySelector("#inputGraph");
                    try {
                        g = graphlibDot.read(inputGraph.value);
                    } catch (e) {
                        inputGraph.setAttribute("class", "error");
                        throw e;
                    }

                    g.graph().transition = function (selection) {
                        return selection.transition().duration(500);
                    };
                    // Render the graph into svg g
                    d3.select("svg g").call(render, g);
                </script>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
